class_name 符箓
extends Node2D

@onready var life_timer: Timer = $LifeTimer
@onready var hitbox_component: HitboxComponent = $HitboxComponent

var direction: Vector2
var source_peer_id: int
var damage: int = 1
var speed: int = 600



func _ready() -> void:
	hitbox_component.damage = damage

	hitbox_component.source_peer_id = source_peer_id

	hitbox_component.hit_hurtbox.connect(_on_hit_hurtbox)
	life_timer.timeout.connect(_on_life_timer_timeout.bind())

func _process(delta: float):
	global_position += direction * speed * delta


func start(direction_context: Vector2):
	self.direction = direction_context

func register_collision():
	hitbox_component.is_hit_handled = true

	queue_free()


func  _on_life_timer_timeout():
	if is_multiplayer_authority():
		queue_free()

func _on_hit_hurtbox(_hurtbox_component: HurtboxComponent):
	register_collision()
